/***************************************************************************
 创建者：华磊
 开始时间：         : 2020.12.19
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   其它指令属性编辑视窗
*                                                                         *
 ***************************************************************************/
#include "otherinstructiondelegate.h"
#include <QDebug>

OtherInstructionDelegate::OtherInstructionDelegate(QWidget *parent):
    QObject(parent)
{
}

void OtherInstructionDelegate::initialView()
{
    otherInstructionView->instruction = "RSR";
    otherInstructionView->selectInstructionType = 0;

    otherInstructionView->rsrIndex = 1;
    otherInstructionView->rsrValue = "ENABLE ";
    otherInstructionView->rsrValueType = 0;
    otherInstructionView->ualmInfo = "UALM";
    otherInstructionView->timerIndex = 1;
    otherInstructionView->timerStatus = "START ";
    otherInstructionView->timerStatusType = 0;
    otherInstructionView->overrideValue = 100;
    otherInstructionView->message = "massage";
    otherInstructionView->jIndex = 1;
    otherInstructionView->jMaxSpeedValue = "R [1]";
    otherInstructionView->lMaxSpeedValue = "100 ";
    otherInstructionView->note = "";

    //otherInstructionView->updateView();
}

void OtherInstructionDelegate::selectJMaxSpeedInstructionSlot()
{
    otherInstructionView->selectInstructionType = EM_OTHER_INSTRUCTION_J_MAX_SPEED;
    otherInstructionView->updateView();

    qDebug("select JOINT_MAX_SPEED instruction");
}

void OtherInstructionDelegate::selectLMaxSpeedInstructionSlot()
{
    otherInstructionView->selectInstructionType = EM_OTHER_INSTRUCTION_L_MAX_SPEED;
    otherInstructionView->updateView();

    qDebug("select LINEAR_MAX_SPEED instruction");
}

void OtherInstructionDelegate::clearNoteSlot()
{
    otherInstructionView->note.clear();

    qDebug("clear note");
}

void OtherInstructionDelegate::finishEditInstructionSlot()
{
    if(EM_OTHER_INSTRUCTION_RSR == otherInstructionView->selectInstructionType)
    {
        otherInstructionView->instruction = "RSR ";
        otherInstructionView->instruction += "[" + QString::number(otherInstructionView->rsrIndex) + "]" + " = ";
        if(0 == otherInstructionView->rsrValueType)
        {
            otherInstructionView->rsrValue = "ENABLE ";
        }
        else
        {
            otherInstructionView->rsrValue = "DISABLE ";
        }

        otherInstructionView->instruction += otherInstructionView->rsrValue;
    }
    else if(EM_OTHER_INSTRUCTION_UALM == otherInstructionView->selectInstructionType)
    {
        otherInstructionView->instruction = "UALM";
        otherInstructionView->instruction += "[" + otherInstructionView->ualmInfo + "]";
    }
    else if(EM_OTHER_INSTRUCTION_TIMER == otherInstructionView->selectInstructionType)
    {
        otherInstructionView->instruction = "TIMER";
        otherInstructionView->instruction += "[" + QString::number(otherInstructionView->timerIndex) + "]" + "=";
        if(0 == otherInstructionView->timerStatusType)
        {
            otherInstructionView->timerStatus = "START";
        }
        else if(1 == otherInstructionView->timerStatusType)
        {
            otherInstructionView->timerStatus = "STOP";
        }
        else if(2 == otherInstructionView->timerStatusType)
        {
            otherInstructionView->timerStatus = "RESET";
        }
        otherInstructionView->instruction += otherInstructionView->timerStatus;
    }
    else if(EM_OTHER_INSTRUCTION_TIMER_2 == otherInstructionView->selectInstructionType)
    {
        otherInstructionView->instruction = "TIMER";
        otherInstructionView->instruction += "[" + QString::number(otherInstructionView->timerIndex) + "]"
                + "=" + otherInstructionView->timerValue;
    }
    else if(EM_OTHER_INSTRUCTION_OVERRIDE == otherInstructionView->selectInstructionType)
    {
        otherInstructionView->instruction = "OVERRIDE";
        otherInstructionView->instruction = otherInstructionView->instruction + "=" + QString::number(otherInstructionView->overrideValue) + "%";
    }
    else if(EM_OTHER_INSTRUCTION_MESSAGE == otherInstructionView->selectInstructionType)
    {
        otherInstructionView->instruction = "MESSAGE";
        otherInstructionView->instruction += "[" + otherInstructionView->message + "]";
    }
    else if(EM_OTHER_INSTRUCTION_J_MAX_SPEED == otherInstructionView->selectInstructionType)
    {
        otherInstructionView->instruction = "JOINT_MAX_SPEED";
        otherInstructionView->instruction += "[" + QString::number(otherInstructionView->jIndex) + "]"
                + "=" + otherInstructionView->jMaxSpeedValue ;
    }
    else if(EM_OTHER_INSTRUCTION_L_MAX_SPEED == otherInstructionView->selectInstructionType)
    {
        otherInstructionView->instruction = "LINEAR_MAX_SPEED";
        otherInstructionView->instruction += "=" + otherInstructionView->lMaxSpeedValue ;
    }

    otherInstructionView->instruction = otherInstructionView->instruction + "; " + "//" + otherInstructionView->note;
}

void OtherInstructionDelegate::selectTimerInstructionSlot()
{
    otherInstructionView->selectInstructionType = EM_OTHER_INSTRUCTION_TIMER;
    otherInstructionView->updateView();
}

void OtherInstructionDelegate::selectTimerInstructionSLot2()
{
    otherInstructionView->selectInstructionType = EM_OTHER_INSTRUCTION_TIMER_2;
    otherInstructionView->updateView();
}
